//
//  YATaskUserLogin.m
//  YoucApi
//
//  Created by Liam on 11/18/12.
//
//

#import "YATaskUserLogin.h"

@implementation YATaskUserLogin

TASK_AUTO_REGISTER(TaskUserLogin);

- (NSString *)_getUriParamA
{
	return @"user_login";
}

- (NSInteger)apiErrorCodeFromErrorCode:(NSInteger)code
{
    switch (code) {
        case 1:
            code = YoucApiErrorInvalidUserNameOrPassword;
            break;
        default:
			code = [super apiErrorCodeFromErrorCode:code];
            break;
    }
    
    return code;
}

- (void)_dealWithJSONResponse:(id)responseObject withError:(NSError *)error
{
	YARespUserLogin *respUserLogin = [[[YARespUserLogin alloc] initWithError:error context:self.context] autorelease];
	
	respUserLogin.userAccount = [self.params objectForKey:KEY_USERACCOUNT];
	
	if ([error code] == YoucApiErrorSuccess)
	{
		NSDictionary *jsonDict = (NSDictionary *)responseObject;
		respUserLogin.session = [jsonDict objectForKey:KEY_SESSION];
		respUserLogin.userId = [jsonDict objectForKey:KEY_UID];
		
		//[APIUtil setSessionKey:respUserLogin.session];
	}
    
	if ([self.delegate respondsToSelector:@selector(userLoginResponse:respUserLogin:)])
	{
		[self.delegate userLoginResponse:self respUserLogin:respUserLogin];
	}
}

@end
